/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.matrimonybeans;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;

/**
 *
 * @author ChauAnh
 */
@Stateless
public class updateProfile implements updateProfileLocal {

    ConnectDB conDB = new ConnectDB();
    Connection conn;

    @Override
    public Boolean setFirstName(String username, String firstName) {
        try {
            conn = conDB.getConnection();
            String strSql = "UPDATE Candidate SET first_name= ? WHERE username= ?";
            PreparedStatement pstmt = conn.prepareCall(strSql);
            pstmt.setString(1, firstName);
            pstmt.setString(2, username);
            int rs = pstmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            try {
                conn.close();
            } catch (SQLException ex) {
                Logger.getLogger(updateProfile.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return false;
    }
    
    public Boolean setMiddleName(String username, String middleName) {
        try {
            conn = conDB.getConnection();
            String strSql = "UPDATE Candidate SET middle_name= ? WHERE username= ?";
            PreparedStatement pstmt = conn.prepareCall(strSql);
            pstmt.setString(1, middleName);
            pstmt.setString(2, username);
            int rs = pstmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            try {
                conn.close();
            } catch (SQLException ex) {
                Logger.getLogger(updateProfile.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return false;
    }
    
    public Boolean setLastName(String username, String lastName) {
        try {
            conn = conDB.getConnection();
            String strSql = "UPDATE Candidate SET last_name= ? WHERE username= ?";
            PreparedStatement pstmt = conn.prepareCall(strSql);
            pstmt.setString(1, lastName);
            pstmt.setString(2, username);
            int rs = pstmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            try {
                conn.close();
            } catch (SQLException ex) {
                Logger.getLogger(updateProfile.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return false;
    }
    
    public Boolean setGender(String username, String gender) {
        try {
            conn = conDB.getConnection();
            String strSql = "UPDATE Candidate SET gender= ? WHERE username= ?";
            PreparedStatement pstmt = conn.prepareCall(strSql);
            pstmt.setString(1, gender);
            pstmt.setString(2, username);
            int rs = pstmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            try {
                conn.close();
            } catch (SQLException ex) {
                Logger.getLogger(updateProfile.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return false;
    }
    
    public Boolean setBirthdate(String username, String birthdate) {
        try {
            conn = conDB.getConnection();
            String strSql = "UPDATE Candidate SET birthdate= ? WHERE username= ?";
            PreparedStatement pstmt = conn.prepareCall(strSql);
            pstmt.setString(1, birthdate);
            pstmt.setString(2, username);
            int rs = pstmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            try {
                conn.close();
            } catch (SQLException ex) {
                Logger.getLogger(updateProfile.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return false;
    }
    
    public Boolean setMaritalStatus(String username, String maritalStatus) {
        try {
            conn = conDB.getConnection();
            String strSql = "UPDATE Candidate SET marital_status= ? WHERE username= ?";
            PreparedStatement pstmt = conn.prepareCall(strSql);
            pstmt.setString(1, maritalStatus);
            pstmt.setString(2, username);
            int rs = pstmt.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            try {
                conn.close();
            } catch (SQLException ex) {
                Logger.getLogger(updateProfile.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return false;
    }
    
}
